我不知道我做错了什么,但每次我尝试测试重定向时,我都会收到此错误:“@requestmustbeanActionDispatch::Request”context"asnon-signedinuser"doit"shouldredirecttotheloginpage"doexpect{visitadmin_account_url(account,host:get_host(account))}.toredirect_to(signin_path)endend1)AdminAccountPagesAdmin::Accounts#showasnon-signedinusershouldr
在Ruby单元测试中,如何断言字符串包含子字符串?像这样的东西:assert_containsstring_to_test,substring_to_verify 最佳答案 您可以使用assert_matchpattern,string,[message]如果string=~pattern为真:assert_matchsubstring_to_verify,string_to_test例如assert_match/foo/,"foobar"如果你经常使用它,为什么不写你自己的断言呢?require'test/unit'moduleT
我刚刚开始使用RubyonRails。来自Java世界,我想知道的一件事是Ruby/Rails开发人员如何找到实际定义方法的位置。即使在第三方库中(假设我有源代码),我也习惯于单击Eclipse中的方法来查找定义的位置。一个具体的例子:我试图找出Authlogicgem如何明显地改变我的User类的构造函数以需要一个额外的参数(称为:password_confirmation),即使User类甚至没有继承任何与Authlogic相关的东西.可能我只是忽略了这里非常明显的东西(或者我仍然无法理解整个“约定优于配置”的事情;-)) 最佳答案
几乎我遇到的每一个规范文件我最终都会写这样的东西:before:eachdo@cimg=Factory.build:cimg_valid@cimg.stub(:validate_img).and_returntrue@cimg.stub(:validate_img_url).and_returntrue@cimg.stub(:save_images).and_returntrue@cimg.stub(:process_image).and_returntrue@cimg.stub(:img).and_returntrueend我的意思是,我从Factory.build获得的模型是完全有
我是测试和Rails的新手,但我正努力让我的TDD流程正常运行。我想知道您是否使用任何类型的范例来测试has_many:through关系?(或者我想一般来说只是has_many)。例如,我发现在我的模型规范中,我肯定会编写简单的测试来检查关系两端的相关方法。即:require'spec_helper'describePostdobefore(:each)do@attr={:subject=>"f00PostSubject",:content=>"8arPostBodyContent"}enddescribe"validations"do...enddescribe"categoriz
我正在尝试运行Rails(4.1.2)控制台railscRAILS_ENV=test我得到这个:>config.eager_loadissettonil.Pleaseupdateyour>config/environments/*.rbfilesaccordingly:>>*development-setittofalse*test-setittofalse(unless>youuseatoolthatpreloadsyourtestenvironment)*production->setittotrue>>/Users/xxxxxx/.rvm/gems/ruby-2.2.2/gems
在Rails3.2.9中,我有如下定义的自定义错误页面:#application.rbconfig.exceptions_app=self.routes#routes.rbmatch'/404'=>'errors#not_found'效果如预期。当我在development.rb中设置config.consider_all_requests_local=false时,我在访问/foo时得到了not_foundView/p>但是我该如何使用Rspec+Capybara来测试呢?我已经试过了:#/spec/features/not_found_spec.rbrequire'spec_hel
假设我有一个带有redirect_to_baz方法的FoosController。classFoosController我正在使用spec/controllers/foos_controller_spec.rb对此进行测试:require'spec_helper'describeFoosController,:type=>:controllerdodescribe"GETredirect_to_baz"doit"redirectstoexample.comwithparams"doget:redirect_to_bazexpect(response).toredirect_to"htt
我正在开发一个依赖于许多自定义Rake任务的ROR应用程序。测试它们的最佳方法是什么? 最佳答案 类似于:defexecute_rake(file,task)require'rake'rake=Rake::Application.newRake.application=rakeRake::Task.define_task(:environment)load"#{Rails.root}/lib/tasks/#{file}"rake[task].invokeend根据您的规范:execute_rake("tags.rake","tags
我的基本逻辑是在某个地方运行一个无限循环并尽可能地测试它。无限循环的原因并不重要(游戏的主循环,类似守护进程的逻辑......)而且我更多地询问关于这种情况的最佳实践。让我们以这段代码为例:moduleBlahextendselfdefrunsome_initializer_methodloopdosome_other_methodyet_another_methodendendend我想使用Rspec测试方法Blah.run(我也使用RR,但简单的rspec将是一个可接受的答案)。我认为最好的方法是分解更多,比如将循环分离成另一个方法或其他东西:moduleBlahextendsel